#include <stdio.h>
#include <string.h>


struct diandef
{
	int x,y,z;
}start,end,queue[2][300000];

int level,row,col;
char map[33][33][33];
int search[33][33][33];
int ndian;



void wfs()
{
	int one,two;
	int n1,n2;
	int find, i, j;
	int movex[]={1,-1, 0, 0, 0, 0};
	int movey[]={0, 0, 1,-1, 0, 0};
	int movez[]={0, 0, 0, 0, 1,-1};
	diandef to,from;
	
	one=0;
	two=1;	
	memset(search,0,sizeof(search));
	queue[one][1]=start;
	search[start.x][start.y][start.z]=1;
	n1=1;
	n2=0;
	find=0;
	while (n1!=0)
	{
		
		for (i=1; i<=n1; i++)
		{
			from=queue[one][i];
			if (from.x==end.x && from.y==end.y &&from.z==end.z )
			{
				find=1;
				break;
			}
			for (j=0;j<6;j++)
			{
				to.x=from.x+movex[j];
				to.y=from.y+movey[j];
				to.z=from.z+movez[j];
				if (search[to.x][to.y][to.z]==0 && map[to.x][to.y][to.z]!='#'
					&& to.x>=1 && to.x<=level 
					&& to.y>=0 && to.y<row 
					&& to.z>=0 && to.z<col	)
				{
					n2++;
					queue[two][n2]=to;
					search[to.x][to.y][to.z]=search[from.x][from.y][from.z]+1;
				}
			}
			
		}
		if (find) break;
		one=one^1;
		two=two^1;
		n1=n2;
		n2=0;


	} // end of while 
	if (find) printf("Escaped in %d minute(s).\n",search[end.x][end.y][end.z]-1);
	else printf("Trapped!\n");

}


main()
{
	int i, j, k;

//	freopen("input_d","r",stdin);
//	freopen("dungeon.in","r",stdin);
	while (1)
	{
		scanf("%d%d%d", &level, &row, &col);   // readdata
		if (level==0) break;
		memset(map,'#',sizeof(map));
		for (i=1;i<=level;i++)
		{
			for (j=0;j<row;j++)
				scanf("%s", map[i][j]);
		}
		
		ndian=0;   // find entrance and exit
		for (k=1;k<=level;k++)
		{
			for (i=0;i<row;i++)
				for (j=0;j<col;j++)
				{
					if     (map[k][i][j]=='.') 
					{
					
					}
					else if (map[k][i][j]=='S')  
					{
						start.x=k;
						start.y=i;
						start.z=j;
					}
					else if (map[k][i][j]=='E')  
					{
						end.x=k;
						end.y=i;
						end.z=j;
					}
				}
		}


		
		wfs();




	}
	return 0;
}